package com.piece.core.web.authority.token;

import lombok.Getter;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import java.util.Collection;

/**
 * 租户认证token
 */
@Getter
public class UsernameAuthenticationToken extends AbstractAuthenticationToken {

    private String clientId;
    private Object principal;
    private Object credentials;

    public UsernameAuthenticationToken(Object principal, Object credentials, String clientId) {
        super(null);
        super.setAuthenticated(false);

        this.principal = principal;
        this.credentials = credentials;
        this.clientId = clientId;
    }

    public UsernameAuthenticationToken(Object principal, Object credentials, Object details, Collection<? extends GrantedAuthority> authorities, String clientId) {
        super(authorities);
        super.setDetails(details);
        super.setAuthenticated(true);

        this.principal = principal;
        this.credentials = credentials;
        this.clientId = clientId;
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }

    @Override
    public Object getCredentials() {
        return this.credentials;
    }

    @Override
    public void setAuthenticated(boolean isAuthenticated) {
        super.setAuthenticated(isAuthenticated);
    }

    @Override
    public void eraseCredentials() {
        super.eraseCredentials();
    }
}
